//
//  SleepViewController.m
//  20170207
//
//  Created by xuPeng on 2017/9/21.
//  Copyright © 2017年 一直丶黑曼巴. All rights reserved.
//
#import "Header.h"
#import "SleepViewController.h"

@interface SleepViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong)UICollectionView *collectionView;
@property (nonatomic, strong)NSArray *arr;
@property (nonatomic, strong)UILabel *lab;
@property (nonatomic, strong)UILabel *lab1;
@property (nonatomic, strong)UILabel *lab2;
@property (nonatomic, strong)UILabel *lab3;
@end

@implementation SleepViewController
- (NSArray *)arr{
    if (!_arr) {
        _arr = @[@"永",@"不",@"休",@"眠"];
    }
    return _arr;
}
- (UILabel *)lab{
    if (!_lab) {
        _lab = [[UILabel alloc] initWithFrame:CGRectMake(PW/4, PH/4,100, 100)];
        _lab.center = CGPointMake(PW/4, PH/4);
        _lab.adjustsFontSizeToFitWidth = YES;
        _lab.textAlignment = NSTextAlignmentCenter;
        _lab.font = [UIFont systemFontOfSize:50];
        _lab.text = @"永";
    }
    return _lab;
}
- (UILabel *)lab1{
    if (!_lab1) {
        _lab1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        _lab1.center = CGPointMake(PW/4, PH/4);
        _lab1.font = [UIFont systemFontOfSize:50];
        _lab1.textAlignment = NSTextAlignmentCenter;
        _lab1.text = @"不";
    }
    return _lab1;
}
- (UILabel *)lab2{
    if (!_lab2) {
        _lab2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        _lab2.center = CGPointMake(PW/4, PH/4);
         _lab2.font = [UIFont systemFontOfSize:50];
        _lab2.textAlignment = NSTextAlignmentCenter;
        _lab2.text = @"休";
    }
    return _lab2;
}
- (UILabel *)lab3{
    if (!_lab3) {
        _lab3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        _lab3.center = CGPointMake(PW/4, PH/4);
         _lab3.font = [UIFont systemFontOfSize:50];
        _lab3.textAlignment = NSTextAlignmentCenter;
        _lab3.text = @"眠";
    }
    return _lab3;
}
- (UICollectionView *)collectionView{
    if (!_collectionView) {
        // 设置collectionView的滚动方向，需要注意的是如果使用了collectview的headerview或者footview的话，如果设置了水平滚动的话，那么久只有宽度起作用了
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
//        layout.itemSize = CGSizeMake((PW-20)/2, PH/2);
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, PW, PH) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor orangeColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    }
    return _collectionView;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [UIApplication sharedApplication].idleTimerDisabled = YES;
     [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    [self.view addSubview:self.collectionView];
}

- (void)viewWillAppear:(BOOL)animated{
    
    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)viewWillDisappear:(BOOL)animated{
    
    self.tabBarController.tabBar.hidden = NO;
    
}
- (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths{


}
/** 总共多少组*/
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.arr.count;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- ( UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * const reuseIdentifier = @"cell";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1];

    if (indexPath.row ==  0) {
//        self.lab .center = cell.center;
         [cell addSubview:self.lab];
    }else  if (indexPath.row == 1) {
//        self.lab1 .center = cell.center;
         [cell addSubview:self.lab1];
    }else  if (indexPath.row ==  2) {

        [cell addSubview:self.lab2];
    }else  if (indexPath.row ==  3) {

        [cell addSubview:self.lab3];
    }
    return cell;
}

#pragma mark -- UICollectionViewDelegateFlowLayout
/** 每个cell的尺寸*/
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(PW/2, (PH-64)/2);
}

//每个section中不同的行之间的行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
@end
